package com.xuyiwei.mayi.jobhandler;

/**
 * Created by xuyiwei on 2019/4/23.
 */

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * 任务Handler的一个Demo（Bean模式）
 *
 * 开发步骤： 1、继承 “IJobHandler” ； 2、装配到Spring，例如加 “@Service” 注解； 3、加 “@JobHander”
 * 注解，注解value值为新增任务生成的JobKey的值;多个JobKey用逗号分割; 4、执行日志：需要通过 "XxlJobLogger.log"
 * 打印执行日志；
 *
 * @author xuxueli 2015-12-19 19:43:36
 */
@JobHandler(value = "demoJobHandler")
@Service
public class DemoJobHandler extends IJobHandler {
    @Value("${xxl.job.executor.port}")
    private String port;

    @Override
    public ReturnT<String> execute(String s) throws Exception {
        XxlJobLogger.log("XXL-JOB, Hello World." + port);
        System.out.println("XXL-JOB, Hello World." + port);
        for (int i = 0; i < 5; i++) {
            XxlJobLogger.log("beat at:" + i);
            // TimeUnit.SECONDS.sleep(2);
        }
        return ReturnT.SUCCESS;
    }
}

